// Copyright (C) 2016  Francisco Javier Parra <franparpe@openmailbox.org>


// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#include "xmpplar.h"
#include "main-window.h"

xmpplar::xmpplar()
  : Gtk::Application("org.gtkmm.examples.application", Gio::APPLICATION_HANDLES_OPEN)
{
  
}

Glib::RefPtr<xmpplar> xmpplar::create()
{
  return Glib::RefPtr<xmpplar>(new xmpplar());
}


MainWindow* xmpplar::create_appwindow()
{
  MainWindow* mainWindow = new MainWindow();

  // adding the window to the application class
  add_window(*mainWindow);

  mainWindow->signal_hide().connect(sigc::bind<Gtk::Window*>(sigc::mem_fun(*this, &xmpplar::on_hide_window), mainWindow));

  return mainWindow;
}

void xmpplar::on_activate()
{
  // MainWindow* mainWindow = create_appwindow();
  // mainWindow->present();
  // // testing the client
  // MainWindow* altWin = create_appwindow();
  // altWin->present();
  m_mainWindow = create_appwindow();
  m_mainWindow->present();


}

void xmpplar::on_hide_window(Gtk::Window* window)
{
  std::cout << "Window hidden" << "\n";
  delete window;
}


